<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/base.css">
    <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
    
    <h2>user用户的页面...</h2>
    <button onclick="logout()">注销登录</button>
    <script>

        function logout(){
            //直接从本地存储里面干掉token
            localStorage.removeItem("token")
        }

        //前端每次发起请求的时候需要携带token传给后端
        let token = localStorage.getItem("token")
        $.ajax({
            url:"http://localhost:3000/api/user",   //app.all("/api/*")
            headers:{
                token
            },
            success:result=>{
                console.log(result)
            }
        })



        // $.ajax({
        //     url:"http://localhost:3000/api/login",
        //     method:"post",
        //     data:{
        //         username:"alex",
        //         password:"abc123"
        //     },
        //     success:result=>{
        //         console.log(result)
        //         localStorage.setItem("token",result.token)
        //     }
        // })

    </script>
</body>
</html>